home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / kernel / dev / devEmulexTape.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-19  |  4.0 KB  |  126 lines

  1. /* 
  2.  * devEmulexTape.c --
  3.  *
  4.  *      Procedures that set up command blocks and process sense
  5.  *    data for Emulex tape drives.
  6.  *
  7.  * Copyright 1986 Regents of the University of California
  8.  * All rights reserved.
  9.  * Permission to use, copy, modify, and distribute this
  10.  * software and its documentation for any purpose and without
  11.  * fee is hereby granted, provided that the above copyright
  12.  * notice appear in all copies.  The University of California
  13.  * makes no representations about the suitability of this
  14.  * software for any purpose.  It is provided "as is" without
  15.  * express or implied warranty.
  16.  */
  17.  
  18. #ifndef lint
  19. static char rcsid[] = "$Header: /cdrom/src/kernel/Cvsroot/kernel/dev/devEmulexTape.c,v 9.1 91/08/19 13:47:25 jhh Exp $ SPRITE (Berkeley)";
  20. #endif not lint
  21.  
  22.  
  23. #include <sprite.h>
  24. #include <dev.h>
  25. #include <devInt.h>
  26. #include <sys/scsi.h>
  27. #include <scsiDevice.h>
  28. #include <scsiHBA.h>
  29. #include <scsiTape.h>
  30. #include <emulexTape.h>
  31.  
  32. /*
  33.  * Sense data returned from the Emulex tape controller in the shoeboxes.
  34.  */
  35. #define EMULEX_SENSE_BYTES    11
  36. typedef struct {
  37.     ScsiClass7Sense    extSense;    /* 8 Bytes */
  38.     unsigned char pad1        :1;
  39.     unsigned char error        :7;    /* Regular SCSI error code */
  40.     unsigned char highRetries;        /* High byte of retry count */
  41.     unsigned char lowRetries;        /* Low byte of retry count */
  42. } EmulexTapeSense;            /* Known to be 11 Bytes big */
  43.  
  44.  
  45. /*
  46.  * Definitions for the mode select command.  This is specific to the
  47.  * Emulex controller.  The mode select command is used to change from
  48.  * QIC_24 format (one standard, not the one we use) to QIC_02 format
  49.  * (the more common, older, standard that we do use).
  50.  */
  51.  
  52. typedef struct EmulexModeSelBlock {
  53.     unsigned char density;        /* Density code */
  54.     unsigned char highCount;        /* Count of blocks at this density */
  55.     unsigned char midCount;        /*    middle byte of above */
  56.     unsigned char lowCount;        /*    low byte */
  57.     unsigned char pad1;            /* Reserved */
  58.     unsigned char highLength;        /* Length of the blocks */
  59.     unsigned char midLength;        /*    middle byte of above */
  60.     unsigned char lowLength;        /*    low byte */
  61. } EmulexModeSelBlock;
  62.  
  63. /*
  64.  * Density values for the mode select block.
  65.  */
  66. #define EMULEX_QIC_24    0x05
  67. #define EMULEX_QIC_02    0x84
  68.  
  69. typedef struct EmulexModeSelParams {
  70.     ScsiTapeModeSelectHdr    header;
  71.     EmulexModeSelBlock    block;
  72.     unsigned char        :5;    /* Reserved */
  73.     unsigned char disableErase    :1;    /* disable erase ahead */
  74.     unsigned char autoLoadInhibit :1;
  75.     unsigned char softErrorCount  :1;
  76. } EmulexModeSelParams;
  77.  
  78.  
  79. /*
  80.  *----------------------------------------------------------------------
  81.  *
  82.  * DevEmulexAttach --
  83.  *
  84.  *    Verify and initialize the attached scsi device as a emulex tape..
  85.  *
  86.  * Results:
  87.  *    SUCCESS if the device is a working emulex tape drive.
  88.  *    DEV_NO_DEVICE if the device is not a emulex tape drive.
  89.  *    A Sprite return status if the device is a broken emulex tape drive.
  90.  *
  91.  * Side effects:
  92.  *    Sets the type and call-back procedures.
  93.  *
  94.  *----------------------------------------------------------------------
  95.  */
  96. /*ARGSUSED*/
  97. ReturnStatus
  98. DevEmulexAttach(devicePtr, devPtr, tapePtr)
  99.     Fs_Device    *devicePtr;    /* Fs_Device being attached. */
  100.     ScsiDevice    *devPtr;    /* SCSI device handle for drive. */
  101.     ScsiTape    *tapePtr;    /* Tape drive state to be filled in. */
  102. {
  103.     ScsiCmd        senseCmd;
  104.     ReturnStatus    status;
  105.     static char        senseData[SCSI_MAX_SENSE_LEN];
  106.     int            length;
  107.     /*
  108.      * Since we don't know about the inquiry data (if any) returned by 
  109.      * the Emulex tape, check using the size of the SENSE data returned.
  110.      */
  111.     DevScsiSenseCmd(devPtr, SCSI_MAX_SENSE_LEN, senseData, &senseCmd);
  112.     status = DevScsiSendCmdSync(devPtr, &senseCmd, &length);
  113.     if ( (status != SUCCESS) || 
  114.          (senseCmd.statusByte != 0) ||
  115.      ((senseCmd.senseLen != EMULEX_SENSE_BYTES) &&
  116.       (senseCmd.senseLen != SCSI_MAX_SENSE_LEN) &&
  117.       (senseCmd.senseLen != 14)) ){
  118.     return DEV_NO_DEVICE;
  119.     }
  120.     /*
  121.      * Take all the defaults for the tapePtr.
  122.      */
  123.     tapePtr->name = "Emulex Tape";
  124.     return SUCCESS;
  125. }
  126.